# -*- coding: utf-8 -*-
# @Time     : 2020/8/1 17:39

import asyncio
import time

now = lambda: time.time()


async def func(a):
    print(f"python{a} --> {now()}")
    return f"PYTHON{a} --> {now()}"


async def run1():
    # 任务列表
    tasks = [func(a) for a in range(10)]
    # 方式1
    data1 = await asyncio.wait(tasks)  # data1是一个元组，长度为2
    for data in data1[0]:
        print(data.result())


async def run2():
    # 任务列表
    tasks = [func(a) for a in range(10)]
    # 方式2
    data2 = await asyncio.gather(*tasks)
    for data in data2:
        print(data)


if __name__ == '__main__':
    # 创建事件循环对象
    loop = asyncio.get_event_loop()
    # 开启事件循环
    loop.run_until_complete(run1())
